Skip to content

fix: correctly type callback indices as an array#12393

Merged
kgryte merged 1 commit into
developfrom
philipp/fix-utils-mapnd-callback-indices
May 31, 2026
Merged

fix: correctly type callback indices as an array#12393
kgryte merged 1 commit into
developfrom
philipp/fix-utils-mapnd-callback-indices

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

Description

What is the purpose of this pull request?

This pull request fixes the callback type signatures of map2d, map3d, map4d, and map5d. The Binary and Ternary callback types declared the third argument as index: number, but the implementations invoke the callback with an array of dimension indices (e.g. fcn.call( thisArg, a[ j ], [ i, j ], arr ) in map2d), and the accompanying TSDoc already documents the argument as indices. Specifically, it:

  • retypes the third callback argument from index: number to indices: Array<number> in the Binary and Ternary callback signatures of all four packages, matching both the runtime and the existing @param indices documentation.
  • adds a declaration test in each package exercising a callback that consumes the indices array (the previous tests only used a unary callback, so they did not cover this argument).

All four declaration files and their type tests pass the lint-typescript-declarations-files (expect-type) checks.

One of several follow-up PRs from a @stdlib/utils declaration audit. Opened as a draft for review of the public callback-type change.

Related Issues

Does this pull request have any related issues?

No.

Questions

Any questions for reviewers of this pull request?

No.

Other

Any other information relevant to this pull request? This may include screenshots, references, and/or implementation notes.

Verified against the implementations: each map<n>d passes an n-element index array to the callback. Surfaced by a multi-agent audit of the @stdlib/utils declarations.

Checklist

Please ensure the following tasks are completed before submitting this pull request.

AI Assistance

When authoring the changes proposed in this PR, did you use any kind of AI assistance?

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

If you answered "yes" to using AI assistance, please provide a short disclosure indicating how you used AI assistance.

This PR was authored primarily by Claude Code, which confirmed the callback argument against each implementation, retyped the signatures, added exercising tests, and verified them with the expect-type declaration tests.


@stdlib-js/reviewers

The `Binary` and `Ternary` callback types declared the third argument as
`index: number`, but the implementations invoke the callback with an
array of dimension indices (e.g. `[ i, j ]` for `map2d`, `[ i, j, k ]`
for `map3d`, etc.), and the accompanying TSDoc already documents the
argument as `indices`. Retype the argument as `indices: Array<number>`
in the `Binary` and `Ternary` callback signatures of `map2d`, `map3d`,
`map4d`, and `map5d`, and add declaration tests exercising a callback
that consumes the indices array.

---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown_pkg_readmes
    status: na
  - task: lint_markdown_docs
    status: na
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: na
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: passed
  - task: lint_typescript_tests
    status: passed
  - task: lint_license_headers
    status: passed
---
@stdlib-bot
Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
utils/map2d $\color{green}142/142$
$\color{green}+100.00\%$
$\color{green}13/13$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}142/142$
$\color{green}+100.00\%$
utils/map3d $\color{green}155/155$
$\color{green}+100.00\%$
$\color{green}17/17$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}155/155$
$\color{green}+100.00\%$
utils/map4d $\color{green}168/168$
$\color{green}+100.00\%$
$\color{green}20/20$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}168/168$
$\color{green}+100.00\%$
utils/map5d $\color{green}181/181$
$\color{green}+100.00\%$
$\color{green}23/23$
$\color{green}+100.00\%$
$\color{green}1/1$
$\color{green}+100.00\%$
$\color{green}181/181$
$\color{green}+100.00\%$

The above coverage report was generated for the changes in this PR.

@kgryte kgryte marked this pull request as ready for review May 31, 2026 23:22
@kgryte kgryte requested a review from a team May 31, 2026 23:22
@stdlib-bot stdlib-bot added the Needs Review A pull request which needs code review. label May 31, 2026
@kgryte kgryte changed the title fix: type map2d/map3d/map4d/map5d callback indices as an array fix: correctly type callback indices as an array May 31, 2026
@kgryte kgryte merged commit da8dc3b into develop May 31, 2026
33 checks passed
@kgryte kgryte deleted the philipp/fix-utils-mapnd-callback-indices branch May 31, 2026 23:23
@kgryte kgryte removed the Needs Review A pull request which needs code review. label May 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants